package ninethwork.one;

import java.util.StringTokenizer;

/**
 * @author ：chenzikang
 * @date ： 2020/4/14
 */

public class IDCardIncrease {

    /**
     *插入数值函数
     */
    public static void insert(String num) {
        //创建对象
        StringBuilder stringBuilder = new StringBuilder(num);

        //将年份插入到6位之后
        stringBuilder.insert(6, 19);

        //指定最后一位随机验证码
        String[] temp = { "1", "0", "x", "2", "3", "4", "5", "6", "7", "8", "9" };

        //指定随机数
        int count = (int) (Math.random() * 10);

        //将随机验证码插入到第17位之后
        stringBuilder.insert(17, temp[count]);

        //打印插入后的结果
        System.out.println(stringBuilder.toString());

    }

    public static void main(String[] args) {
        // 方法一

        String sfzMessage = "370102770102413,370102760807911,370102660810114";

        //对字符串进行分割，存入数组
        String[] a = sfzMessage.split(",");

        //调用函数
        insert(a[0]);
        insert(a[1]);
        insert(a[2]);

        // 方法二
        String[] b = new String[3];

        //对字符串进行分割
        StringTokenizer st = new StringTokenizer(sfzMessage, ",");

        //将字符串存入数组
        while (st.hasMoreTokens()) {

            for (int i = 0; i < 3; i++) {
                b[i] = st.nextToken();

            }

        }

        //调用函数插入
        insert(b[0]);
        insert(b[1]);
        insert(b[2]);

    }

}
